Type.registerNamespace('ModWatch');

ModWatch.OnDropDownListChangedModAlertBehavior = function(element) { 
    ModWatch.OnDropDownListChangedModAlertBehavior.initializeBase(this, [element]);

	this._currentSelectedIndex = 0;
	this._previousOnChangeEvent = null;
}

ModWatch.OnDropDownListChangedModAlertBehavior.prototype =
{

	_onChange : function(e)
	{
		if (!ModWatch.OnDropDownListChangedModAlertBehavior.callBaseMethod(this, 'verifyChanges'))
		{
			this.get_element().selectedIndex = this._currentSelectedIndex;
			return false;
		}
		else
		{
			this._currentSelectedIndex = this.get_element().selectedIndex;

			if (this._previousOnChangeEvent != null)
				return this._previousOnChangeEvent(e);
		}
	},

	initialize : function()
	{
		ModWatch.OnDropDownListChangedModAlertBehavior.callBaseMethod(this, 'initialize');

		var ddl = this.get_element();
		var currentChangeEvent = ddl.onchange;
		if (typeof currentChangeEvent == 'function')
		{
			this._previousOnChangeEvent = currentChangeEvent;
		}

		this._currentSelectedIndex = ddl.selectedIndex;

		$addHandlers(this.get_element(), 
					 { 'change' : this._onChange },
					 this);

		ddl.onchange = null;
	},

	dispose : function()
	{
		this.get_element().onchange = this._previousOnChangeEvent;

		$clearHandlers(this.get_element());

		ModWatch.OnDropDownListChangedModAlertBehavior.callBaseMethod(this, 'dispose');
	}

}

ModWatch.OnDropDownListChangedModAlertBehavior.registerClass('ModWatch.OnDropDownListChangedModAlertBehavior', ModWatch.ModAlertBehaviorBase);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
